<?php
/** .-------------------------------------------------------------------
 * |  Software: [HDCMS framework]
 * |      Site: www.hdcms.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

namespace app\api\controller;

class User {
	/**
	 * @api {get} ?s=api/user/one&id=用户编号 获取一个用户
	 * @apiSampleRequest ?s=api/user/one
	 * @apiPermission 无
	 * @apiName one
	 * @apiGroup user
	 * @apiVersion 1.0.0
	 * @apiDescription   api   获取一个用户
	 *
	 * @apiParam {Number} id  学生编号    (必填).
	 *
	 * @apiSuccessExample Success-Response:
	 *     HTTP/1.1 200 OK
	 *     {
	 *       "valid": 1,
	 *       "data": [
	 *           {
	 *              "id: "学生编号",
	 *              "username": "学生名称",
	 *           }
	 *       ]
	 *     }
	 *
	 *
	 * @apiErrorExample Error-Response:
	 *     HTTP/1.1 404 Not Found
	 *      {
	 *          "valid": 0,
	 *          "message":"错误信息"
	 *      }
	 */
	public function one() {
		$data = Db::table( 'user' )->find( Request::get( 'id' ) );
		ajax( [ 'code' => 0, 'data' => $data ] );
	}

	/**
	 * @api {get} ?s=api/user/get&row=数量 获取用户列表
	 * @apiSampleRequest ?s=api/user/get
	 * @apiPermission 无
	 * @apiName get
	 * @apiGroup user
	 * @apiVersion 1.0.0
	 * @apiDescription   api   获取用户列表
	 *
	 * @apiParam {Number} row  条数    (必填).
	 *
	 * @apiSuccessExample Success-Response:
	 *     HTTP/1.1 200 OK
	 *     {
	 *       "valid": 1,
	 *       "data": [
	 *           {
	 *              "id: "学生编号",
	 *              "username": "学生名称",
	 *           }
	 *       ]
	 *     }
	 *
	 *
	 * @apiErrorExample Error-Response:
	 *     HTTP/1.1 404 Not Found
	 *      {
	 *          "valid": 0,
	 *          "message":"错误信息"
	 *      }
	 */
	public function get() {
		$data = Db::table( 'user' )->limit(Request::get('row'))->get();
		ajax( [ 'code' => 0, 'data' => $data ] );
	}
	/**
	 * @api {get} ?s=api/user/getByName&username=用户名 根据用户名获取用户信息
	 * @apiSampleRequest ?s=api/user/getByName
	 * @apiPermission 无
	 * @apiName getByName
	 * @apiGroup user
	 * @apiVersion 1.0.0
	 * @apiDescription   api   根据用户名获取用户信息
	 *
	 * @apiParam {String} username  用户名    (必填).
	 *
	 * @apiSuccessExample Success-Response:
	 *     HTTP/1.1 200 OK
	 *     {
	 *       "valid": 1,
	 *       "data": [
	 *           {
	 *              "id: "学生编号",
	 *              "username": "学生名称",
	 *           }
	 *       ]
	 *     }
	 *
	 *
	 * @apiErrorExample Error-Response:
	 *     HTTP/1.1 404 Not Found
	 *      {
	 *          "valid": 0,
	 *          "message":"错误信息"
	 *      }
	 */
	public function getByName() {
		$data = Db::table( 'user' )->where('username',Request::get('username'))->first();
		ajax( [ 'code' => 0, 'data' => $data ] );
	}

//	测试
	/**
	 * @api {get} ?s=api/user/getThree&three=3 获取前三条用户名数据
	 * @apiSampleRequest ?s=api/user/getThree
	 * @apiPermission 无
	 * @apiName getThree
	 * @apiGroup user
	 * @apiVersion 1.0.0
	 * @apiDescription   api   获取三条用户数据
	 *
	 *
	 * @apiSuccessExample Success-Response:
	 *     HTTP/1.1 200 OK
	 *     {
	 *       "valid": 1,
	 *       "data": [
	 *           {
	 *              "id: "学生编号",
	 *              "username": "学生名称",
	 *           }
	 *       ]
	 *     }
	 *
	 *
	 * @apiErrorExample Error-Response:
	 *     HTTP/1.1 404 Not Found
	 *      {
	 *          "valid": 0,
	 *          "message":"错误信息"
	 *      }
	 */
	public function getThree() {
		$data = Db::table( 'user' )->limit(3)->get();
		ajax( [ 'code' => 0, 'data' => $data ] );
	}
}
